#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;

class Solution{
    public:
    //回溯问题--数独
    bool ans1(vector<vector<char>>& board){
        int rows[9][9];
        int cols[9][9];
        int sub[3][3][9];
        
        memset(rows, 0, sizeof(rows));
        memset(cols, 0, sizeof(cols));
        memset(sub, 0, sizeof(sub));

        for(int i = 0; i != 9; i++){
            for(int j = 0; j != 9; j++){
                char c = board[i][j];
                if(c != '.'){
                    int index = c - '0' - 1;
                    rows[i][index]++;
                    cols[j][index]++;
                    sub[i/3][j/3][index]++;
                    if(rows[i][index] > 1 || cols[j][index] > 1 || sub[i/3][j/3][index] > 1){
                        return false;
                    }
                }

            }
        }
        return true;
    }

};

void test1(){
    Solution s;
    vector<vector<char>> val = {
        {'5','3','.','.','7','.','.','.','.'},
        {'6','.','.','1','9','5','.','.','.'},
        {'.','9','8','.','.','.','.','6','.'},
        {'8','.','.','.','6','.','.','.','3'},
        {'4','.','.','8','.','3','.','.','1'},
        {'7','.','.','.','2','.','.','.','6'},
        {'.','6','.','.','.','.','2','8','.'},
        {'.','.','.','4','1','9','.','.','5'},
        {'.','.','.','.','8','.','.','7','9'}
        };
    
    bool ret = s.ans1(val);
    cout << ret << endl;
}

int main(void){
    test1();

    return 0;
}